//
//  KnowDetailsViewController.m
//  EMMApp
//
//  Created by Mac on 16/5/12.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "KnowDetailsViewController.h"
#import "KnowDetailCell.h"
#import "GetPayDepositDetailApi.h"
#import "NewFromViewController.h"
#import "BusinessAuditApi.h"
#import "AddSubscriptionViewController.h"
#import "GetSubscribeDetail.h"
#import "AddNewSignViewController.h"
#import "MHPhotoBrowserController.h"

@interface KnowDetailsViewController ()<UITableViewDelegate,UITableViewDataSource> {
    NSString *konwSyting;
    NSString *distinguish;
    NSMutableDictionary *dic;//存对应的数据
    NSMutableArray *selectedArr;//二级列表是否展开状态
    NSMutableArray *titleDataArray;
    NSArray *dataArray;//数据源，显示每个cell的数据
    NSMutableDictionary *stateDic;//三级列表是否展开状态
    NSMutableArray *grouparr1;
    NSMutableArray *grouparr2;
    NSMutableArray *grouparr4;
    NSMutableArray *grouparr0;
    NSMutableArray *grouparr3;
    
    NSMutableArray *grouparr5;
    NSMutableArray *grouparr6;

    NSInteger heightCell;
    
    UITableView *_cellTableView;
    NSMutableDictionary *diccell;//存对应的数据
    NSMutableArray *selectedArrcell;//二级列表是否展开状态
    NSMutableArray *titleDataArraycell;
    NSArray *dataArraycell;//数据源，显示每个cell的数据
}

@property (nonatomic, strong) UITableView *knowDtailTableView;

@property (nonatomic, strong) UIButton *bhButton;

@property (nonatomic, strong) UIButton *tgButton;

@property (nonatomic, strong) UIButton *rcButton;

@property (nonatomic, strong) UIButton *rgButton;

@property (nonatomic, strong) UIButton *qyButton;
@property (nonatomic, strong) UIView *showUIView;

@property (nonatomic,strong) NSMutableArray *customerFamilyList;

@property (nonatomic, strong) GetPayDepositDetail *getPayDepositDetail;

/**
 *
 */
//合同扫描件数组
@property (nonatomic, strong) NSMutableArray *imageList;
//合同扫描件数组1
@property (nonatomic, strong) NSMutableArray *imageUrlList;

@property (nonatomic, strong) NSMutableArray *annexListArr;

@end

@implementation KnowDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _customerFamilyList = [[NSMutableArray alloc] init];
    _imageList = [[NSMutableArray alloc] init];
    _imageUrlList = [[NSMutableArray alloc] init];
    _annexListArr = [[NSMutableArray alloc] init];
    
    if ([NSString isStringEmpty2:self.businessId]== YES) {
        [self postGetPayDepositDetailApiPayDepositId:_payDepositId];
    }else {
        [self postGetPayDepositDetailApiPayDepositId:_businessId];
    }
    [self creatNavigationController];
    self.view.backgroundColor = [UIColor colorFromHexCode:@"#f5f5f5"];
    dic = [[NSMutableDictionary alloc] init];
    selectedArr = [[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4", nil];
    dataArray = [[NSArray alloc] init];
    
    diccell = [[NSMutableDictionary alloc] init];
    selectedArrcell = [[NSMutableArray alloc] init];
    dataArraycell = [[NSArray alloc] init];
    
    _knowDtailTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 90.5, EMM_WIDTH, EMM_HEIGHT-90.5-50-SafeAreaTopHeight) style:UITableViewStylePlain];
    _knowDtailTableView.delegate = self;
    _knowDtailTableView.dataSource = self;
    _knowDtailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _knowDtailTableView.showsVerticalScrollIndicator = NO;
    _knowDtailTableView.backgroundColor = [UIColor colorFromHexCode:@"#f5f5f5"];
    [self.view addSubview:_knowDtailTableView];
    heightCell = 0;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backPushNotification:) name:@"isBackPushNotification" object:nil];
}

- (void)backPushNotification:(NSNotification *)notification {
    [self dismissViewControllerAnimated:NO completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)creatNavigationController {
    [self updateNavBar];
    self.navigationItem.title = @"认筹详情";
//    [self configLeftBtn];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0, 0, 54 ,44)];
    [backBtn addTarget:self
                action:@selector(notBtnClick:)
      forControlEvents:UIControlEventTouchUpInside];
    [backBtn setBackgroundColor:[UIColor clearColor]];
    [backBtn setImage:[UIImage imageNamed:@"ico_back"] forState:UIControlStateNormal];
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    if (EMM_WIDTH <= 320) {
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }else if (EMM_WIDTH > 375){
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }else{
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}

- (void)notBtnClick:(UIButton *)btn {
    if (_isNot == YES) {
        [self.navigationController popViewControllerAnimated:YES];
    }else {
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
}


#pragma mark - post
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

#pragma mark - 查看认筹详情接口
- (void)postGetPayDepositDetailApiPayDepositId:(NSString *)payDepositId {
    [self showHud:@"正在加载请稍等..."];
    [_customerFamilyList removeAllObjects];
    [_imageList removeAllObjects];
    [_imageUrlList removeAllObjects];
    [_annexListArr removeAllObjects];

    GetPayDepositDetailApi *api = [[GetPayDepositDetailApi alloc] initWithPayDepositId:payDepositId isAudit:self.isAudit];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetPayDepositDetailApi *result = (GetPayDepositDetailApi *)request;
        if (result.isSuccess) {
            GetPayDepositDetail *get = result.resultData;
            _getPayDepositDetail = get;
            [self creatShowUI];
             [self initDataSource];
            ////1 提交审核 2审核中 3审核驳回 4审核成功
            //0表示案场经理 1表示经纪人
            if ([NSString isStringEmpty2:self.businessId]== YES) {
                [self creatInitWithButtonsShowUI];
                
            }else {
                [self creatInitWithBusinessIdShowUI];
            }
            for (CustomerFamilyList *list in get.customerFamilyList) {
                [_customerFamilyList addObject:list];
            }
            if (_customerFamilyList.count > 0) {
                heightCell = 200*_customerFamilyList.count;
            }else {
                heightCell = 0;
            }
            
            for (ImageList *list in get.imageList) {
                [_imageList addObject:list];
                [_imageUrlList addObject:list.smallUrl];
            }
            
            for (AnnexList *list in get.annexList) {
                [_annexListArr addObject:list];
            }
            
            [_cellTableView reloadData];
            [_knowDtailTableView reloadData];
            
        } else {
            //[self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                [appInstance showLogin];
                
            } else if ( [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

- (void)creatShowUI {
    self.userNameLabel.text = _getPayDepositDetail.customerName;
    if ([NSString isStringEmpty2:_getPayDepositDetail.customerStar] == NO) {
        if ([_getPayDepositDetail.customerStar isEqualToString:@"是"]) {
            self.customerStar.hidden = NO;
            self.sexLabel.layer.masksToBounds = YES;
            self.sexLabel.layer.cornerRadius = 5;
            self.sexLabel.backgroundColor = [UIColor colorFromHexCode:@"#f7653e"];
            self.sexLabel.text = _getPayDepositDetail.customerSex;
            self.gradeLabel.layer.masksToBounds = YES;
            self.gradeLabel.layer.cornerRadius = 5;
            self.gradeLabel.text = _getPayDepositDetail.intentionLevel;
            self.gradeLabel.backgroundColor = [UIColor colorFromHexCode:@"#f82b49"];
        }else {
            self.customerStar.hidden = YES;
            self.sex1Label.layer.masksToBounds = YES;
            self.sex1Label.layer.cornerRadius = 5;
            self.sex1Label.backgroundColor = [UIColor colorFromHexCode:@"#f7653e"];
            self.sex1Label.text = _getPayDepositDetail.customerSex;
            self.grade1Label.layer.masksToBounds = YES;
            self.grade1Label.layer.cornerRadius = 5;
            self.grade1Label.text = _getPayDepositDetail.intentionLevel;
            self.grade1Label.backgroundColor = [UIColor colorFromHexCode:@"#f82b49"];
        }
    }
    self.phoneLabel.text = _getPayDepositDetail.customerPhone;
    self.kfLabel.text = _getPayDepositDetail.customerOrigin;
    self.qyLabel.text = _getPayDepositDetail.customerStatus;
    self.kfLabel.textColor = [UIColor colorFromHexCode:@"#ff7200"];
    self.qyLabel.textColor = [UIColor colorFromHexCode:@"#ff7200"];

}

- (void)creatInitWithBusinessIdShowUI {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, EMM_HEIGHT-50-SafeAreaTopHeight, EMM_WIDTH, 50)];
//    view.backgroundColor = [UIColor colorFromHexCode:@"#00bcbd"];
    [self.view addSubview:view];
    UIView *hxView = [[UIView alloc] initWithFrame:CGRectMake(EMM_WIDTH/2-0.5, 20, 1, 20)];
    hxView.backgroundColor = [UIColor whiteColor];
    _bhButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _bhButton.frame = CGRectMake(0, 0, EMM_WIDTH/2, 50);
    [_bhButton setTitle:@"退回" forState:UIControlStateNormal];
    [_bhButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _bhButton.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    [_bhButton addTarget:self action:@selector(bhButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_bhButton];
    _tgButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _tgButton.frame = CGRectMake(EMM_WIDTH/2, 0, EMM_WIDTH/2, 50);
    [_tgButton setTitle:@"成功" forState:UIControlStateNormal];
    [_tgButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_tgButton addTarget:self action:@selector(tgButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    _tgButton.backgroundColor = [UIColor colorFromHexCode:@"#c4302c"];
    [view addSubview:_tgButton];
//    [view addSubview:hxView];
}

- (void)creatInitWithButtonsShowUI {
    _showUIView = [[UIView alloc] initWithFrame:CGRectMake(0, EMM_HEIGHT-50-SafeAreaTopHeight, EMM_WIDTH, 50)];
//    _showUIView.backgroundColor = [UIColor colorFromHexCode:@"#00bcbd"];
    if ([_getPayDepositDetail.auditStatus isEqualToString:@"审核中"]) {
        _knowDtailTableView.frame = CGRectMake(0, 90.5, EMM_WIDTH, EMM_HEIGHT-90.5-SafeAreaTopHeight);
    }else {
        [self.view addSubview:_showUIView];
        _knowDtailTableView.frame = CGRectMake(0, 90.5, EMM_WIDTH, EMM_HEIGHT-90.5-50-SafeAreaTopHeight);
    }
    UIView *hxView = [[UIView alloc] initWithFrame:CGRectMake(EMM_WIDTH/2-0.5, 20, 1, 20)];
    hxView.backgroundColor = [UIColor whiteColor];
    //0、待提交；1、审核中；2、驳回；3、成功
    if ([_getPayDepositDetail.auditStatus isEqualToString:@"待提交"] || [_getPayDepositDetail.auditStatus isEqualToString:@"已退回"]) {
        _rcButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _rcButton.frame = CGRectMake(0, 0, EMM_WIDTH, 50);
        [_rcButton setTitle:@"认  筹" forState:UIControlStateNormal];
        _rcButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_rcButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rcButton.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
        [_rcButton addTarget:self action:@selector(rcButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_showUIView addSubview:_rcButton];
    }else if ([_getPayDepositDetail.auditStatus isEqualToString:@"审核中"]) {
        _showUIView.backgroundColor = [UIColor whiteColor];
    }else if ([_getPayDepositDetail.auditStatus isEqualToString:@"已通过"]) {
        _rgButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _rgButton.frame = CGRectMake(0, 0, EMM_WIDTH/2, 50);
        [_rgButton setTitle:@"认购" forState:UIControlStateNormal];
        [_rgButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_rgButton addTarget:self action:@selector(rgButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _rgButton.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
        [_showUIView addSubview:_rgButton];
        _qyButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _qyButton.frame = CGRectMake(EMM_WIDTH/2, 0, EMM_WIDTH/2, 50);
        [_qyButton setTitle:@"签约" forState:UIControlStateNormal];
        [_qyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_qyButton addTarget:self action:@selector(qyButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _qyButton.backgroundColor = [UIColor colorFromHexCode:@"#c4302c"];
        [_showUIView addSubview:_qyButton];
//        [_showUIView addSubview:hxView];
    }
}

#pragma mark - 修改认筹
- (void)rcButtonClick:(UIButton *)btn {
    NewFromViewController *kvc = [[NewFromViewController alloc] init];
    kvc.isFrom = @"1";
    kvc.getPayDepositDetail = _getPayDepositDetail;
    kvc.followUpViewBlock = ^{
        [self postGetPayDepositDetailApiPayDepositId:_payDepositId];
        _showUIView.hidden = YES;
    };
    [self.navigationController pushViewController:kvc animated:YES];
}

#pragma mark - 认购
- (void)rgButtonClick:(UIButton *)btn {
    
    if ([NSString isStringEmpty2:_getPayDepositDetail.payDepositRoomType] == NO) {
        [self showToast:_getPayDepositDetail.payDepositRoomeMsg];
        return;
    }else {
        GetSubscribeDetail *get = [[GetSubscribeDetail alloc] init];
        
        get.payDepositId = _getPayDepositDetail.payDepositId;
        get.payDepositCode = _getPayDepositDetail.payDepositCode;
        get.payDepositMoney = _getPayDepositDetail.payDepositMoney;
        
        if ([NSString isStringEmpty2:_getPayDepositDetail.discountAmount] == NO) {
            get.discountAmount = [NSString getMoney2:[_getPayDepositDetail.discountAmount floatValue]];
        }else {
            get.discountAmount = @"";
        }
        get.payDepositId = _getPayDepositDetail.payDepositId;
        if ([_getPayDepositDetail.floorType isEqualToString:@"0"]) {
            get.discountRate = [NSString getMoney2:[_getPayDepositDetail.discountRate floatValue]*100];
        }else {
            get.discountRate = [NSString getMoney2:[_getPayDepositDetail.discountRate floatValue]*100];
        }
        get.roomId = _getPayDepositDetail.roomId;
        get.calculateArea = _getPayDepositDetail.calculateArea;
        get.discountPrice = _getPayDepositDetail.discountPrice;
        get.discountTotalPrice = _getPayDepositDetail.discountTotalPrice;
        get.paymentMethod = self.paymentMethod;
        get.realAmount = _getPayDepositDetail.realAmount;
        get.floorType = _getPayDepositDetail.floorType;
        get.contractAmount = _getPayDepositDetail.discountTotalPrice;//合同金额
        float dis3 = [_getPayDepositDetail.calculateArea floatValue];
        float price = [_getPayDepositDetail.discountTotalPrice floatValue];
        get.contractPrice = [NSString getMoney2:price/dis3];
        AddSubscriptionViewController *nvc = [[AddSubscriptionViewController alloc] init];
        nvc.isSFNew = @"0";
        
        get.subscribeHouses = _getPayDepositDetail.payDepositHouses;
        if ([NSString isStringEmpty2:_getPayDepositDetail.payDepositHouses] == NO) {
            nvc.isrcNew = @"1";
        }else {
            nvc.isrcNew = nil;
        }
        
        nvc.customerId = self.customerId;
        nvc.getSubscribeDetail = get;
//        [self.navigationController pushViewController:nvc animated:YES];
        if ([NSString isStringEmpty:_getPayDepositDetail.enough] == NO) {
            if ([_getPayDepositDetail.enough isEqualToString:@"1"]) {
                [self.navigationController pushViewController:nvc animated:YES];
            }else {
                [self showToast:@"认筹金未收满"];
            }
        }else {
            [self showToast:@"认筹金不能为空"];
        }
    }
}

#pragma mark - 签约
- (void)qyButtonClick:(UIButton *)btn {
   
    if ([NSString isStringEmpty2:_getPayDepositDetail.payDepositRoomType] == NO) {
        [self showToast:_getPayDepositDetail.payDepositRoomeMsg];
        return;
    }else {
        AddNewSignViewController *nvc = [[AddNewSignViewController alloc] init];
        nvc.isAdd = YES;
        nvc.floorType = nil;
        nvc.busReturnType = @"1";
        nvc.customerId = self.customerId;
        nvc.payDepositId = _getPayDepositDetail.payDepositId;
        nvc.payDepositCode = _getPayDepositDetail.payDepositCode;
        nvc.payDepositMoney = _getPayDepositDetail.payDepositMoney;
        if ([NSString isStringEmpty2:_getPayDepositDetail.roomId] == NO) {
            nvc.konString = @"1";
        }else {
            nvc.konString = @"0";
        }
        if ([NSString isStringEmpty2:_getPayDepositDetail.discountAmount] == NO) {
            nvc.discountAmount = [NSString getMoney2:[_getPayDepositDetail.discountAmount floatValue]];
        }else {
            nvc.discountAmount = nil;
        }
        if ([_getPayDepositDetail.floorType isEqualToString:@"0"]) {
            nvc.discountRate = [NSString getMoney2:[_getPayDepositDetail.discountRate floatValue]*100];
        }else {
            nvc.discountRate = [NSString getMoney2:[_getPayDepositDetail.discountRate floatValue]*100];
        }
        nvc.qyRoomName = _getPayDepositDetail.payDepositHouses;
        nvc.qyRoomId = _getPayDepositDetail.roomId;
        nvc.calculateArea = _getPayDepositDetail.calculateArea;
        nvc.discountPrice = _getPayDepositDetail.discountPrice;
        nvc.discountTotalPrice = _getPayDepositDetail.discountTotalPrice;
        nvc.paymentMethod = self.paymentMethod;
        nvc.floorType = _getPayDepositDetail.floorType;
        nvc.realAmount = _getPayDepositDetail.realAmount;
        nvc.istpoy = @"1";
        nvc.jJRDataArr = [[NSMutableArray alloc] init];
        nvc.contractAmount = _getPayDepositDetail.discountTotalPrice;//合同金额
        float dis3 = [_getPayDepositDetail.calculateArea floatValue];
        float price = [_getPayDepositDetail.discountTotalPrice floatValue];
        nvc.contractPrice = [NSString getMoney2:price/dis3];
        
        if ([NSString isStringEmpty:_getPayDepositDetail.enough] == NO) {
            if ([_getPayDepositDetail.enough isEqualToString:@"1"]) {
                [self.navigationController pushViewController:nvc animated:YES];
            }else {
                [self showToast:@"认筹金未收满"];
            }
        }else {
            [self showToast:@"认筹金不能为空"];
        }
    }
}

#pragma mark - 驳回
- (void)bhButtonClick:(UIButton *)btn {
    EMMAlertViewController *alertVC = [[EMMAlertViewController alloc] initWithtitile:@"审核退回" confirmTitle:@"确认" cancelTitle:@"取消" confirmAction:^(NSString *inputText) {
        NSLog(@"%@",inputText);
        [self postBusinessAuditApiAuditStatus:@"2" remark:inputText];
    } andCancelAction:^{
        NSLog(@"1");
    }];
    [self presentViewController:alertVC animated:YES completion:nil];
}

#pragma mark - 成功
- (void)tgButtonClick:(UIButton *)btn {
    EMMAlertViewController *alertVC = [[EMMAlertViewController alloc] initWithtitile:@"审核成功" confirmTitle:@"确认" cancelTitle:@"取消" confirmAction:^(NSString *inputText) {
        NSLog(@"%@",inputText);
        [self postBusinessAuditApiAuditStatus:@"1" remark:inputText];
    } andCancelAction:^{
        NSLog(@"1");
    }];
    
    [self presentViewController:alertVC animated:YES completion:nil];
}

-(void)initDataSource
{
    titleDataArraycell = [[NSMutableArray alloc] init];
    titleDataArray = [[NSMutableArray alloc] initWithObjects:@"认筹信息",@"房源信息", @"客户信息",@"附件",@"审核信息", nil];
    grouparr0 = [[NSMutableArray alloc] initWithObjects:@"业务状态", nil];
    [dic setValue:grouparr0 forKey:@"0"];
    grouparr2 = [[NSMutableArray alloc]initWithObjects:@"客户姓名",@"证件类型",@"证件号码",@"手机号码",@"邮寄地址",@"邮  编", @"", @"认筹编号",@"认筹金",@"已收认筹金",@"经纪人",@"认筹日期",@"备注",nil];
    
    [dic setValue:grouparr2 forKey:@"2"];
    if ([_getPayDepositDetail.isPayDeposit isEqualToString:@"1"]) {
        grouparr4 = [[NSMutableArray alloc] initWithObjects:@"无房认筹", nil];
        [dic setValue:grouparr4 forKey:@"1"];
    }else  {
        grouparr1 = [[NSMutableArray alloc] initWithObjects:@"无房认筹",@"认筹房源",@"计价面积",@"折前单价",@"折前总价", nil];
        [dic setValue:grouparr1 forKey:@"1"];
    }
    grouparr0 = [[NSMutableArray alloc]initWithObjects:@"客户姓名",@"证件类型",@"证件号码", nil];
    
    grouparr5 = [[NSMutableArray alloc]initWithObjects:@"",@"", nil];
    [dic setValue:grouparr5 forKey:@"3"];
    
    grouparr6 = [[NSMutableArray alloc]initWithObjects:@"审核状态",@"理由",@"审核人",@"审核时间", nil];
    [dic setValue:grouparr6 forKey:@"4"];
}

#pragma mark - UITableView代理
//返回几个表头
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView == _cellTableView) {
        return _customerFamilyList.count;
    }
    return titleDataArray.count;
}

//每一个表头下返回几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == _cellTableView) {
        return grouparr0.count;
    }
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if ([selectedArr containsObject:string]) {
        NSArray *array1 = dic[string];
        return array1.count;
    }
    return 0;
}

//设置表头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}

//Section Footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (tableView == _cellTableView) {
        return 0.2;
    }
    return 5;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 5)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

//设置view，将替代titleForHeaderInSection方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (tableView == _cellTableView) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
        view.backgroundColor = [UIColor whiteColor];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, tableView.frame.size.width-20, 20)];
        titleLabel.text = [NSString stringWithFormat:@"客户信息%ld", section+1];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        [view addSubview:titleLabel];
        view.backgroundColor = [UIColor colorFromHexCode:@"#fff5e9"];
        UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 4, 30)];
        sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
        [view addSubview:sLabel6];
        return view;
    }
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, tableView.frame.size.width-20, 20)];
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
    titleLabel.text = [titleDataArray objectAtIndex:section];
    [view addSubview:titleLabel];
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 49.5, EMM_WIDTH, 0.5)];
    lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, EMM_WIDTH, 50);
    button.tag = 100+section;
    [button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    view.backgroundColor = [UIColor colorFromHexCode:@"#fff5e9"];
    UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 4, 30)];
    sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    [view addSubview:sLabel6];
  
    UIImageView *upImageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-30, 20, 20, 10)];
    [view addSubview:upImageView];
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if ([selectedArr containsObject:string]) {
        upImageView.image = [UIImage imageNamed:@"sanjt_down"];
    }else {
        upImageView.image = [UIImage imageNamed:@"sanjt_up"];
    }
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];
    if ([indexStr isEqualToString:@"1"]) {
        if (indexPath.row == 1) {
            NSInteger h = [IDTools textHeightFromTextString:_getPayDepositDetail.payDepositHouses width:[UIScreen mainScreen].bounds.size.width-115 fontSize:15]+30;
            if (h <= 50) {
                h = 50;
            }
            return h;
        }
        return 50;
    }else if ([indexStr isEqualToString:@"2"]) {
        if (indexPath.row == 4) {
            CGSize titleSize = [_getPayDepositDetail.mailPost boundingRectWithSize:CGSizeMake(EMM_WIDTH - 107, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
            int h = titleSize.height + 33;
            if (h <= 50) {
                h = 50;
            }
            return h;
        }else if (indexPath.row == 6) {
            return heightCell;
        }else if (indexPath.row == 12) {
            CGSize titleSize = [_getPayDepositDetail.remark boundingRectWithSize:CGSizeMake(EMM_WIDTH - 107, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
            int h = titleSize.height + 33;
            if (h <= 50) {
                h = 50;
            }
            return h;
        }
    }else if ([indexStr isEqualToString:@"3"]) {
        if (indexPath.row == 0) {
            if (_imageList.count > 0) {
                return 100;
            }else {
                return 0;
            }
        }else if (indexPath.row == 1) {
            if ([NSString isStringEmpty2:_getPayDepositDetail.annexNum] == NO && ![_getPayDepositDetail.annexNum isEqualToString:@"0"]) {
                
                return _annexListArr.count * 50 +50;
            }else {
                if (_imageList.count == 0) {
                    return 120;
                }else {
                    return 0;
                }
            }
        }
    }
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _cellTableView) {
        static NSString *CellIdentifier = @"KnowDetailCellId";
        KnowDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"KnowDetailCell" owner:self options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLabel.text = [grouparr0 objectAtIndex:indexPath.row];
        UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
        lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
        [cell addSubview:lineImage];
        CustomerFamilyList *list = [_customerFamilyList objectAtIndex:indexPath.section];
        if (indexPath.row == 0) {
            if ([NSString isStringEmpty2:list.memberName] == YES) {
                cell.fbTitleLabel.text = @"";
            }else {
                 cell.fbTitleLabel.text = list.memberName;
            }
        }else if (indexPath.row == 1) {
            if ([NSString isStringEmpty2:list.documentType] == YES) {
                cell.fbTitleLabel.text = @"";
            }else {
                cell.fbTitleLabel.text = list.documentType;
            }
        }else if (indexPath.row == 2) {
            if ([NSString isStringEmpty2:list.documentNumber] == YES) {
                cell.fbTitleLabel.text = @"";
            }else {
                cell.fbTitleLabel.text = list.documentNumber;
            }
        }
        return cell;
    }
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];
    NSLog(@"%@",indexStr);
    static NSString *CellIdentifier = @"KnowDetailCellId";
    KnowDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"KnowDetailCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([selectedArr containsObject:indexStr]) {
        cell.titleLabel.text = dic[indexStr][indexPath.row];
    }
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
    lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    [cell addSubview:lineImage];
   
    
    if ([indexStr isEqualToString:@"0"]) {
        if (indexPath.row == 0) {
           cell.fbTitleLabel.text = _getPayDepositDetail.businessStatus;
        }
    }else if ([indexStr isEqualToString:@"1"]) {
        if ([_getPayDepositDetail.isPayDeposit isEqualToString:@"1"]) {
            cell.fbTitleLabel.text = @"是";
        }else {
            if (indexPath.row == 0) {
               cell.fbTitleLabel.text = @"否";
            }else if (indexPath.row == 1) {
                NSInteger h = [IDTools textHeightFromTextString:_getPayDepositDetail.payDepositHouses width:[UIScreen mainScreen].bounds.size.width-115 fontSize:15]+30;
                if (h > 50) {
                    lineImage.frame = CGRectMake(10, h - 0.5, EMM_WIDTH-20, 0.5);
                }
                cell.fbTitleLabel.text = _getPayDepositDetail.payDepositHouses;
            }else if (indexPath.row == 2) {
                if ([NSString isStringEmpty2:_getPayDepositDetail.calculateArea] == NO) {
                    cell.fbTitleLabel.text = [NSString stringWithFormat:@"%@m²",_getPayDepositDetail.calculateArea];
                }else {
                    cell.fbTitleLabel.text = @"m²";
                }
            }else if (indexPath.row == 3) {
                if ([NSString isStringEmpty2:_getPayDepositDetail.discountPrice] == NO) {
                    cell.fbTitleLabel.text = [NSString stringWithFormat:@"%@元",_getPayDepositDetail.discountPrice];
                }else {
                    cell.fbTitleLabel.text = @"元";
                }
            }else if (indexPath.row == 4) {
                cell.fbTitleLabel.text = _getPayDepositDetail.discountTotalPrice;
                if ([NSString isStringEmpty2:_getPayDepositDetail.discountTotalPrice] == NO) {
                    cell.fbTitleLabel.text = [NSString stringWithFormat:@"%@元",_getPayDepositDetail.discountTotalPrice];
                }else {
                    cell.fbTitleLabel.text = @"元";
                }
            }
        }
    }else if ([indexStr isEqualToString:@"2"]) {
        if (indexPath.row == 0) {
            cell.fbTitleLabel.text = _getPayDepositDetail.customerName;
        }else if (indexPath.row == 1) {
            cell.fbTitleLabel.text = _getPayDepositDetail.documentType;
        }else if (indexPath.row == 2) {
            cell.fbTitleLabel.text = _getPayDepositDetail.documentNumber;
        }else if (indexPath.row == 3) {
             cell.fbTitleLabel.text = _getPayDepositDetail.customerPhone;
        }else if (indexPath.row == 4) {
            CGSize titleSize = [_getPayDepositDetail.mailPost boundingRectWithSize:CGSizeMake(EMM_WIDTH - 107, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
            int h = titleSize.height + 33;
            if (h <= 50) {
                h = 50;
            }
            lineImage.frame = CGRectMake(10, h - 0.5, EMM_WIDTH - 20, 0.5);
            if ([NSString isStringEmpty2:_getPayDepositDetail.mailPost] == NO) {
                cell.fbTitleLabel.text = _getPayDepositDetail.mailPost;
            }
        }else if (indexPath.row == 5) {
            if ([NSString isStringEmpty2:_getPayDepositDetail.postcode] == NO) {
                cell.fbTitleLabel.text = _getPayDepositDetail.postcode;
            }
        }else if (indexPath.row == 6) {
            _cellTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH,heightCell) style:UITableViewStyleGrouped];
            _cellTableView.delegate = self;
            _cellTableView.dataSource = self;
            _cellTableView.showsVerticalScrollIndicator = NO;
            _cellTableView.scrollEnabled = NO;
            //        _cellTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            [cell addSubview:_cellTableView];
        }else if (indexPath.row == 7) {
            cell.fbTitleLabel.text = _getPayDepositDetail.payDepositCode;
        }else if (indexPath.row == 8) {
            cell.fbTitleLabel.text = [NSString stringWithFormat:@"%@元",_getPayDepositDetail.payDepositMoney];
        }else if (indexPath.row == 9) {
            cell.fbTitleLabel.text = [NSString stringWithFormat:@"%@元",_getPayDepositDetail.realAmount];
        }else if (indexPath.row == 10) {
            cell.fbTitleLabel.text = _getPayDepositDetail.agentId;
        }else if (indexPath.row == 11) {
            cell.fbTitleLabel.text = _getPayDepositDetail.payDepositDate;
        }else if (indexPath.row == 12) {
            CGSize titleSize = [_getPayDepositDetail.remark boundingRectWithSize:CGSizeMake(EMM_WIDTH - 107, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
            int h = titleSize.height + 33;
            if (h <= 50) {
                h = 50;
            }
            lineImage.frame = CGRectMake(10, h - 0.5, EMM_WIDTH - 20, 0.5);
            cell.fbTitleLabel.text = _getPayDepositDetail.remark;
        }
    }else if ([indexStr isEqualToString:@"3"]) {
        
        if (indexPath.row == 0) {
            cell.titleLabel.hidden = YES;
            UIImageView *im = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
            [cell addSubview:im];
            UILabel *labelNum = [[UILabel alloc] initWithFrame:CGRectMake(95, 70, 100, 20)];
            labelNum.font = [UIFont systemFontOfSize:13];
            [cell addSubview:labelNum];
            lineImage.hidden = YES;
            if (_imageList.count > 0) {
                lineImage.hidden = NO;
                
                ImageList *list = [_imageList objectAtIndex:0];
                [im sd_setImageWithURL:[NSURL URLWithString:list.smallUrl] placeholderImage:nil];
                labelNum.text = [NSString stringWithFormat:@"(%ld)",_imageList.count];
                lineImage.frame = CGRectMake(10, 100-0.5, EMM_WIDTH-20, 0.5);
                
                UIButton *seeButton = [UIButton buttonWithType:UIButtonTypeSystem];
                seeButton.frame = CGRectMake(10, 10, 80, 80);
                [seeButton addTarget:self action:@selector(seeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:seeButton];
            }
        }else if (indexPath.row == 1) {
            if ([NSString isStringEmpty2:_getPayDepositDetail.annexNum] == NO && ![_getPayDepositDetail.annexNum isEqualToString:@"0"]) {
                
                UIImageView *tsIm = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 20, 20)];
                tsIm.image = [UIImage imageNamed:@"tishi"];
                [cell addSubview:tsIm];
                
                UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(35, 0, EMM_WIDTH-20, 50)];
                nameL.text = [NSString stringWithFormat:@"存在以下%@个非图片附件，请通过电脑端查看",_getPayDepositDetail.annexNum];
                nameL.font = [UIFont systemFontOfSize:15];
                nameL.textColor = [UIColor orangeColor];
                nameL.numberOfLines = 0;
                //                nameL.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];
                [cell addSubview:nameL];
                cell.titleLabel.hidden = YES;
                
                for (int i = 0; i < _annexListArr.count; i++) {
                    AnnexList *list = [_annexListArr objectAtIndex:i];
                    
                    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50+i*50, EMM_WIDTH, 50)];
                    
                    UILabel *touistsTLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 10, 10)];
                    touistsTLabel.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
                    touistsTLabel.layer.masksToBounds = YES;
                    touistsTLabel.layer.cornerRadius = 5;
                    [view addSubview:touistsTLabel];
                    
                    UILabel *touistsNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 0, EMM_WIDTH-35, 50)];
                    touistsNameLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                    touistsNameLabel.font = [UIFont systemFontOfSize:15];
                    touistsNameLabel.textAlignment = NSTextAlignmentLeft;
                    touistsNameLabel.text = list.annexName;
                    touistsNameLabel.numberOfLines = 0;
                    [view addSubview:touistsNameLabel];
                    UIImageView *V1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                    V1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                    [view addSubview:V1];
                    [cell addSubview:view];
                }
            }else {
                //                cell.titleLabel.text = @"暂无附件";
                if (_imageList.count == 0) {
                    cell.titleLabel.hidden = YES;
                    UIImageView *wfjIm = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH/2-65, 10, 130, 100)];
                    wfjIm.image = [UIImage imageNamed:@"saomiao"];
                    [cell addSubview:wfjIm];
                    lineImage.hidden = YES;
                }
            }
        }
    }else if ([indexStr isEqualToString:@"4"]) {
        if (indexPath.row == 0) {
            cell.fbTitleLabel.text = _getPayDepositDetail.auditStatus;
        }else if (indexPath.row == 1) {
            cell.fbTitleLabel.text = _getPayDepositDetail.auditReason;
        }else if (indexPath.row == 2) {
            cell.fbTitleLabel.text = _getPayDepositDetail.auditId;
        }else if (indexPath.row == 3) {
            cell.fbTitleLabel.text = _getPayDepositDetail.auditTime;
        }
    }
    return cell;
}

#pragma mark - 查看大图
- (void)seeButtonClick:(UIButton *)btn {
    if (_imageList.count > 0) {
        MHPhotoBrowserController *vc = [MHPhotoBrowserController new];
        NSMutableArray * bigImgArray = [NSMutableArray new];
        for (int i = 0; i < _imageList.count; i++) {
            ImageList *list = [_imageList objectAtIndex:i];
            NSString *url1 = [list.smallUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [bigImgArray addObject:[MHPhotoModel photoWithURL:[NSURL URLWithString:url1]]];
        }
        vc.currentImgIndex = 0;
        vc.displayTopPage = YES;
        vc.displayDeleteBtn = YES;
        vc.imgArray = bigImgArray;
        //        vc.isShouDel = 1;
        vc.displayDeleteBtn = NO;
        [self presentViewController:vc animated:YES completion:nil];
    }else {
        [self showToast:@"暂无图片预览"];
    }
}

-(void)doButton:(UIButton *)sender
{
    NSString *string = [NSString stringWithFormat:@"%ld",sender.tag-100];
    //数组selectedArr里面存的数据和表头想对应，方便以后做比较
    if ([selectedArr containsObject:string]) {
        [selectedArr removeObject:string];
    } else  {
        [selectedArr addObject:string];
    }
    [_knowDtailTableView reloadData];
    [_cellTableView reloadData];
}

- (IBAction)phonebtnClick:(id)sender {
//    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
//    NSString *isPhoneInformation = [userdf objectForKey:@"isPhoneInformation"];
//    if ([NSString isStringEmpty2:isPhoneInformation] == NO) {
//        if ([isPhoneInformation isEqualToString:@"0"]) {
//            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", _getPayDepositDetail.customerPhone];
//            UIWebView * callWebview = [[UIWebView alloc] init];
//            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//            [self.view addSubview:callWebview];
//
//            
//        }else if ([isPhoneInformation isEqualToString:@"1"]) {
//            [self postGetUserCallListApi];
//        }
//    }else {
//        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", _getPayDepositDetail.customerPhone];
//        UIWebView * callWebview = [[UIWebView alloc] init];
//        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//        [self.view addSubview:callWebview];
//
//    }
    [self postGetUserCallListApi];
}

#pragma  mark - 业务审核
- (void)postBusinessAuditApiAuditStatus:(NSString *)auditStatus remark:(NSString *)remark {
    [self showHud:@"正在加载请稍等..."];

    BusinessAuditApi *api = [[BusinessAuditApi alloc] initWithBusinessId:self.businessId
                                                            businessType:@"认筹"
                                                                  taskId:self.taskId
                                                             auditStatus:auditStatus
                                                                  remark:remark];
    
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        BusinessAuditApi *result = (BusinessAuditApi *)request;
        if (result.isSuccess) {
//            BusinessAudit *get = result.resultData;
//            [self.navigationController popViewControllerAnimated:YES];
            if (_isNot == YES) {
                [self.navigationController popViewControllerAnimated:YES];
            }else {
                [self dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }
        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                [appInstance showLogin];
                
            } else if ( [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 查询用户电话列表接口
- (void)postGetUserCallListApi {
    [self showHudInWindow:@"正在加载中..."];
    GetUserCallListApi *api = [[GetUserCallListApi alloc] initWith];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetUserCallListApi *result = (GetUserCallListApi *)request;
        //请求成功
        if (result.isSuccess) {
            GetUserCallList *get = result.resultData;
            if ([NSString isStringEmpty2:get.isPhoneInformation] == NO) {
                if ([get.isPhoneInformation isEqualToString:@"0"]) {
                    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", _getPayDepositDetail.customerPhone];
                    UIWebView * callWebview = [[UIWebView alloc] init];
                    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
                    [self.view addSubview:callWebview];
                }else {
                    UserCallMenuView *userListV = [[UserCallMenuView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT) title:@"选择拨打号码" nameArr:get.userCallList];
                    userListV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                    [[UIApplication sharedApplication].keyWindow addSubview:userListV];
                    __weak UserCallMenuView *weakMenuView = userListV;
                    [userListV setTouchUserCallMenuViewBlock:^(NSString *telePhone, NSString *telePhoneType) {
                        NSLog(@"%@-%@",telePhone,telePhoneType);
                        if ([NSString isStringEmpty2:telePhone] == NO) {
                            [self postGetCallBackApiTelePhoneString:telePhone];
                        }
                        [weakMenuView removeFromSuperview];
                    }];
                }
            }else {
                NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", _getPayDepositDetail.customerPhone];
                UIWebView * callWebview = [[UIWebView alloc] init];
                [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
                [self.view addSubview:callWebview];
            }
        } else {
            
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 查询电话回拨接口
- (void)postGetCallBackApiTelePhoneString:(NSString *)telePhoneString {
    GetCallBackApi *api = [[GetCallBackApi alloc] initWithCustomerId:self.customerId caller:telePhoneString called:_getPayDepositDetail.customerPhone terminalModel:@"0" terminalModelId:self.customerId];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetCallBackApi *result = (GetCallBackApi *)request;
        //请求成功
        if (result.isSuccess) {
            GetCallBack *get = result.resultData;
            FollowUpViewController *fvc = [[FollowUpViewController alloc] init];
            fvc.customerId = self.customerId;
            fvc.followId = get.followId;
            [self.navigationController pushViewController:fvc animated:YES];
        } else {
            
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}
@end
